﻿// -------------------------------------------------------------------------------------------------------------------------------
// <copyright file="TestAssignUInt16.cs" company="Exul">
//     Copyright (c) Exul. All rights reserved.
// </copyright>
// <author>
//     Exul
// </author>
// -------------------------------------------------------------------------------------------------------------------------------

namespace ExulLibrary.Mathematics.LinearAlgebra.Sequential.Tests.RMDenseMatrixTest
{
    #region Usings

    using System;

    using NUnit.Framework;

    #endregion

    /// <summary>
    ///     Test suite for <see cref="RMDenseMatrixExtensions.Assign(RMDenseMatrix{ushort},RMDenseMatrix{ushort})"/>.
    /// </summary>
    [TestFixture]
    [Category("ExulLibrary.Mathematics.LinearAlgebra.Sequential.RMDenseMatrixExtensions")]
    public sealed class TestAssignUInt16
    {
        /// <summary>
        ///     Tests the method when source and target have the same size.
        /// </summary>
        [Test]
        public void WhenSourceAndTargetHaveTheSameSize()
        {
            // Arrange
            var sourceData = new[]
                             {
                                 new ushort[] { 10, 20, 30 },
                                 new ushort[] { 40, 50, 60 }
                             };
            var source = new RMDenseMatrix<ushort>(sourceData);
            var targetData = new[]
                             {
                                 new ushort[] { 1, 2, 3 },
                                 new ushort[] { 4, 5, 6 }
                             };
            var target = new RMDenseMatrix<ushort>(targetData);

            // Act
            target.Assign(source);

            // Assert
            Assert.That(target.Values, Is.Not.SameAs(source.Values) & Is.EquivalentTo(sourceData));
        }

        /// <summary>
        ///     Tests the method when source has less count of rows than target.
        /// </summary>
        [Test]
        public void WhenSourceHasLessRowsCountThanTarget()
        {
            // Arrange
            var sourceData = new[]
                             {
                                 new ushort[] { 10, 20, 30 }
                             };
            var source = new RMDenseMatrix<ushort>(sourceData);
            var targetData = new[]
                             {
                                 new ushort[] { 1, 2, 3 },
                                 new ushort[] { 4, 5, 6 }
                             };
            var target = new RMDenseMatrix<ushort>(targetData);
            var expectedResult = new[]
                                 {
                                     new ushort[] { 10, 20, 30 },
                                     new ushort[] { 4, 5, 6 }
                                 };

            // Act
            target.Assign(source);

            // Assert
            Assert.That(target.Values, Is.Not.SameAs(source.Values) & Is.EquivalentTo(expectedResult));
        }

        /// <summary>
        ///     Tests the method when source has greater count of rows than target.
        /// </summary>
        [Test]
        public void WhenSourceHasGreaterRowsCountThanTarget()
        {
            // Arrange
            var sourceData = new[]
                             {
                                 new ushort[] { 10, 20, 30 },
                                 new ushort[] { 40, 50, 60 },
                                 new ushort[] { 70, 80, 90 }
                             };
            var source = new RMDenseMatrix<ushort>(sourceData);
            var targetData = new[]
                             {
                                 new ushort[] { 1, 2, 3 },
                                 new ushort[] { 4, 5, 6 }
                             };
            var target = new RMDenseMatrix<ushort>(targetData);
            var expectedResult = new[]
                                 {
                                     new ushort[] { 10, 20, 30 },
                                     new ushort[] { 40, 50, 60 }
                                 };

            // Act
            target.Assign(source);

            // Assert
            Assert.That(target.Values, Is.Not.SameAs(source.Values) & Is.EquivalentTo(expectedResult));
        }

        /// <summary>
        ///     Tests the method when source has less count of columns than target.
        /// </summary>
        [Test]
        public void WhenSourceHasLessColumnsCountThanTarget()
        {
            // Arrange
            var sourceData = new[]
                             {
                                 new ushort[] { 10, 20 },
                                 new ushort[] { 30, 40 }
                             };
            var source = new RMDenseMatrix<ushort>(sourceData);
            var targetData = new[]
                             {
                                 new ushort[] { 1, 2, 3 },
                                 new ushort[] { 4, 5, 6 }
                             };
            var target = new RMDenseMatrix<ushort>(targetData);
            var expectedResult = new[]
                                 {
                                     new ushort[] { 10, 20, 3 },
                                     new ushort[] { 30, 40, 6 }
                                 };

            // Act
            target.Assign(source);

            // Assert
            Assert.That(target.Values, Is.Not.SameAs(source.Values) & Is.EquivalentTo(expectedResult));
        }

        /// <summary>
        ///     Tests the method when source has greater count of columns than target.
        /// </summary>
        [Test]
        public void WhenSourceHasGreaterColumnsCountThanTarget()
        {
            // Arrange
            var sourceData = new[]
                             {
                                 new ushort[] { 10, 20, 30, 40 },
                                 new ushort[] { 50, 60, 70, 80 }
                             };
            var source = new RMDenseMatrix<ushort>(sourceData);
            var targetData = new[]
                             {
                                 new ushort[] { 1, 2, 3 },
                                 new ushort[] { 4, 5, 6 }
                             };
            var target = new RMDenseMatrix<ushort>(targetData);
            var expectedResult = new[]
                                 {
                                     new ushort[] { 10, 20, 30 },
                                     new ushort[] { 50, 60, 70 }
                                 };

            // Act
            target.Assign(source);

            // Assert
            Assert.That(target.Values, Is.Not.SameAs(source.Values) & Is.EquivalentTo(expectedResult));
        }

#if SAFE

        /// <summary>
        ///     Tests the method when source is <see langword="null"/>.
        /// </summary>
        [Test]
        public void WhenSourceIsNull()
        {
            // Arrange
            var targetData = new[]
                             {
                                 new ushort[3],
                                 new ushort[3]
                             };
            var target = new RMDenseMatrix<ushort>(targetData);

            // Act and Assert
            Assert.That(
                () => target.Assign(null),
                Throws.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("source"));
        }

        /// <summary>
        ///     Tests the method when target is <see langword="null"/>.
        /// </summary>
        [Test]
        public void WhenTargetIsNull()
        {
            // Arrange
            var sourceData = new[]
                             {
                                 new ushort[3],
                                 new ushort[3]
                             };
            var source = new RMDenseMatrix<ushort>(sourceData);

            // Act and Assert
            Assert.That(
                () => RMDenseMatrixExtensions.Assign(null, source),
                Throws.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("target"));
        }

#endif
    }
}